package com.my.job.quartz.config;

import org.quartz.Scheduler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;


@Configuration
public class QuartzConfigTwo {
    @Autowired
    private SpringJobFactory springJobFactory;

    @Bean
    public SchedulerFactoryBean schedulerFactoryBean() {
        SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
        schedulerFactoryBean.setJobFactory(springJobFactory);
        return schedulerFactoryBean;
    }

    @Bean
    public Scheduler scheduler() {
        return schedulerFactoryBean().getScheduler();
    }

//    @Service
//    public class QuartzEventServiceImpl implements QuartzEventService {
//        private static final String JOB_GROUP = "event_job_group";
//        private static final String TRIGGER_GROUP = "event_trigger_group";
//        @Autowired
//        private Scheduler scheduler;
//
//        @Override
//        public void addQuartz(Event event) throws SchedulerException {
//            JSONObject eventData = JSONObject.parseObject(event.getEventData());
//            Date triggerDate = eventData.getDate("date");
//            JobDetail job = JobBuilder.newJob(EventJob.class).withIdentity(event.getId().toString(), JOB_GROUP).usingJobData(buildJobDateMap(event)).build();
//            Trigger trigger = TriggerBuilder.newTrigger().withIdentity(event.getId().toString(), TRIGGER_GROUP).startAt(triggerDate).build();
//            scheduler.scheduleJob(job, trigger);
//        }
}
